<svg style="display: block; width: 0; height: 0">
  <defs>
    <filter id="merge">
      <femerge>
        <femergenode in="FillPaint"></femergenode>
        <femergenode in="SourceGraphic"></femergenode>
      </femerge>
    </filter>
  </defs>
</svg>
<canvas id="canvas" width="100" height="100"></canvas>
<script>
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
var canvas2 = document.createElement('canvas');
canvas2.width = 20;
canvas2.height = 20;
var ctx2 = canvas2.getContext('2d');

ctx2.fillStyle = '#00f';
ctx2.fillRect(0, 0, canvas2.width, canvas.height);

ctx.filter = 'url(#merge)';
ctx.fillStyle = '#0f0';
ctx.drawImage(canvas2, 40, 40);

ctx.fillStyle = '#ff0';
ctx.drawImage(canvas2, 70, 70);
</script>
